{%- extends "base.html" %}

{%- block title %}
{% trans %}User list{% endtrans %}
{%- endblock %}

{%- block subtitle %}
{{ domain.name }}
{%- endblock %}

{%- block main_action %}
<a class="btn btn-primary float-right" href="{{ url_for('.user_create', domain_name=domain.name) }}">{% trans %}Add user{% endtrans %}</a>
{%- endblock %}

{%- block content %}
{%- call macros.table(order='[[2,"asc"]]') %}
<thead>
  <tr>
    <th data-orderable="false">{% trans %}Actions{% endtrans %}</th>
    <th data-orderable="false">{% trans %}User settings{% endtrans %}</th>
    <th>{% trans %}Email{% endtrans %}</th>
    <th>{% trans %}Features{% endtrans %}</th>
    <th>{% trans %}Quota{% endtrans %}</th>
    <th>{% trans %}Comment{% endtrans %}</th>
    <th>{% trans %}Created{% endtrans %}</th>
    <th>{% trans %}Last edit{% endtrans %}</th>
  </tr>
</thead>
<tbody>
  {%- for user in domain.users %}
  <tr{% if not user.enabled %} class="text-muted"{% endif %}>
    <td>
      <a href="{{ url_for('.user_edit', user_email=user.email) }}" title="{% trans %}Edit{% endtrans %}"><i class="fas fa-pencil-alt"></i></a>&nbsp;
    </td>
    <td>
      <a href="{{ url_for('.user_settings', user_email=user.email) }}" title="{% trans %}Settings{% endtrans %}"><i class="fa fa-wrench"></i></a>&nbsp;
      <a href="{{ url_for('.user_reply', user_email=user.email) }}" title="{% trans %}Auto-reply{% endtrans %}"><i class="fa fa-plane"></i></a>&nbsp;
      {%- if config["FETCHMAIL_ENABLED"] -%}
      <a href="{{ url_for('.fetch_list', user_email=user.email) }}" title="{% trans %}Fetched accounts{% endtrans %}"><i class="fa fa-download"></i></a>&nbsp;
      {%- endif -%}
    </td>
    <td>{{ user }}</td>
    <td data-sort="{{ user.allow_spoofing*4 + user.enable_imap*2 + user.enable_pop }}">
      {% if user.enable_imap %}<span class="badge bg-primary">imap</span>{% endif %}
      {% if user.enable_pop %}<span class="badge bg-secondary">pop3</span>{% endif %}
      {% if user.allow_spoofing %}<span class="badge bg-danger">allow-spoofing</span>{% endif %}
    </td>
    <td data-sort="{{ user.quota_bytes_used }}">{{ user.quota_bytes_used | filesizeformat }} / {{ (user.quota_bytes | filesizeformat) if user.quota_bytes else '∞' }}</td>
    <td>{{ user.comment or '-' }}</td>
    <td data-sort="{{ user.created_at or '0000-00-00' }}">{{ user.created_at | format_date }}</td>
    <td data-sort="{{ user.updated_at or '0000-00-00' }}">{{ user.updated_at | format_date }}</td>
  </tr>
  {%- endfor %}
</tbody>
{%- endcall %}
{%- endblock %}
